<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // GET 请求 POST add
        // xhr XMLRequest
        const xhr = new XMLHttpRequest();
        let name = '黄煜';
        xhr.onreadystatechange = function() {
            if (httpRequest.readyState == XMLHttpRequest.DONE) {
                console.log('保存成功');
            }
        }
        xhr.open('POST', "http://localhost:3000/users") // 建立一个连接
            // 如果是post 要带表单数据
            // POST 请求比GET 请求更安全，encode 编码一下
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xhr.send('name=' + encodeURIComponent(name));
    </script>
</body>

</html>